<template>
  <div>
    <div class="imgWrite-top">
      <h4 style="text-align: left; color: #126bff; margin-bottom: 20px">
        图文上报管理
      </h4>
      <el-form
        ref="elForm"
        :model="formData"
        size="medium"
        label-width="115px"
        style="width: 100%; display: flex; flex-wrap: wrap"
        id="elForm"
      >
        <el-form-item
          label="护卫学校名称 ："
          prop="dwmc"
          style="width: 450px; float: left"
        >
          <el-input
            v-model="formData.dwmc"
            placeholder="请输入护卫学校"
            clearable
            style="float: left"
            :style="{ width: '300px' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item
          label="上报人姓名 ："
          prop="xm"
          style="width: 450px; float: left"
        >
          <el-input
            v-model="formData.xm"
            placeholder="请输入姓名"
            clearable
            style="float: left"
            :style="{ width: '300px' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item
          label="上报时段 ："
          prop="time"
          style="width: 450px; float: left"
        >
          <el-date-picker
            type="daterange"
            v-model="formData.time"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            :style="{ width: '300px' }"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            range-separator="至"
            clearable
          ></el-date-picker>
        </el-form-item>
        <el-form-item size="medium" style="float: right">
          <el-button @click="resetForm()" size="medium" id="reset"
            >重置</el-button
          >
          <el-button
            type="primary"
            size="medium"
            @click="submitForm(formData)"
            id="submitForm"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="warn-content" style="width: 100%">
      <exportExcel
        :Data="Data"
        :jsonFields="jsonFields"
        :title="title"
        @BulkExport="BulkExport"
      ></exportExcel>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="序号" width="100">
          <template slot-scope="scope">
            {{ scope.$index + 1 + (currentPage - 1) * pageSize }}
          </template>
        </el-table-column>
        <el-table-column prop="dwmc" label="护卫学校名称"> </el-table-column>
        <el-table-column prop="ssjwsq" label="所属派出所"> </el-table-column>
        <el-table-column prop="xm" label="上报人姓名"> </el-table-column>
        <el-table-column prop="tm_xlmj_lxdh" label="上报人手机号">
          <template slot-scope="scope">
            <span v-if="scope.row.showIdCard">{{ scope.row.xlmj_lxdh }}</span>
            <span v-else>{{ scope.row.tm_xlmj_lxdh }}</span>
            <!-- <el-button
              type="text"
              icon="el-icon-view"
              @click="scope.row.showIdCard = !scope.row.showIdCard"
            ></el-button> -->
            <!-- show(scope.row) -->
          </template>
        </el-table-column>
        <el-table-column prop="title" label="标题"> </el-table-column>
        <el-table-column prop="content" label="正文内容" width="300">
          <template v-slot="scope">
            <span class="rowText">{{ scope.row.content }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="imgSrc" label="照片" width="200">
          <template v-slot="scope">
            <el-image
              style="
                width: 50px;
                height: 50px;
                padding: 5px;
                box-sizing: border-box;
              "
              :src="scope.row.img_one"
              v-if="scope.row.img_one"
              :preview-src-list="[scope.row.img_one]"
            >
            </el-image>
            <el-image
              style="
                width: 50px;
                height: 50px;
                padding: 5px;
                box-sizing: border-box;
              "
              :src="scope.row.img_two"
              v-if="scope.row.img_two"
              :preview-src-list="[scope.row.img_two]"
            >
            </el-image>
            <el-image
              style="
                width: 50px;
                height: 50px;
                padding: 5px;
                box-sizing: border-box;
              "
              :src="scope.row.img_three"
              v-if="scope.row.img_three"
              :preview-src-list="[scope.row.img_three]"
            >
            </el-image>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="上报时间" width="160">
        </el-table-column>
        <!-- <el-table-column prop="address" label="上报地址"></el-table-column> -->
        <el-table-column label="操作">
          <template slot-scope="scope">
            <!-- {{ userInfo.resources.detailMenu }} -->
            <el-button @click="handleClick(scope.row)" type="text" size="small"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div style="display: flex; flex-direction: row-reverse">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          layout="total, prev, pager, next, sizes"
          :total="total"
          style="float: right"
        >
        </el-pagination>
      </div>
    </div>

    <div>
      <detailDialog
        :dialogVsible="Visible"
        :detail="detaile"
        :imgvisible="imgvisible"
        @handel="handel"
        @Confirm="Confirm"
      ></detailDialog>
    </div>
  </div>
</template>
<script>
import { imageTextLoggl } from "@/api/school/imgWrite";
import { Loading } from "element-ui";
import { department } from "@/api/departant";
import detailDialog from "@/components/detailDetail";
import exportExcel from "@/components/exportExcel";
// import Maps from "@/components/MapData";
export default {
  name: "WARN",
  components: { detailDialog, exportExcel },
  data() {
    return {
      totalLength: "",
      Visible: false,
      imgvisible: false,
      // showIdCard: false,
      userInfo: JSON.parse(localStorage.getItem("userInfo")),
      currentPage4: 4,
      // 按页数查询数据
      currentPage: 1,
      pageSize: 10,
      Data: [],
      title: "",
      jsonFields: {
        学校名称: "dwmc",
        所属派出所: "ssjwsq",
        标题: "title",
        正文内容: "content",
        上报人姓名: "xm",
        上报人手机号: "tm_xlmj_lxdh", //常规字段
        照片: "img_one",
        时间: "create_time",
      },
      optionsOne: [],
      emitPath: false,
      selectId: {
        dpid: "",
      },
      // 条件搜索表单数据
      formData: {
        dwmc: "", //护卫学校名称
        xm: "", // 上报人姓名
        time: "",
        page: 1,
        pagesize: 20,
        token: JSON.parse(localStorage.getItem("userInfo")).user.token,
      },
      // 条件搜索使用数据
      searchData: {
        dwmc: "", //护卫学校名称
        xm: "", // 上报人姓名
        begin_time: "", // 开始时间
        end_time: "", // 结束时间
        // department_id: "", //所属派出所 id
        page: 1,
        pagesize: 20,
        token: JSON.parse(localStorage.getItem("userInfo")).user.token,
      },
      detaile: {},
      tableData: [],
      dialogVisible: false,
      imgSrc: require("@/assets/pagesImg/4392.png"),
      a: false,
    };
  },
  watch: {},
  created() {
    // @keydown.enter.native="submitForm(formData)"
  },
  mounted() {
    this.initdata();
    // this.initPolice();
  },

  methods: {
    //  that.Data = res.data.res; 数据导出
    BulkExport() {
      this.title = "图文上报";
      this.Data = this.tableData;
    },
    show(row) {
      this.$nextTick(() => {
        row.showIdCard = !row.showIdCard;
      });

      return row.showIdCard;
    },
    handel(e) {
      console.log("11");
      console.log(e);
      this.Visible = e;
      this.imgvisible = e;
    },
    Confirm(e) {
      console.log("11");
      console.log(e);
      this.Visible = e;
      this.imgvisible = e;
    },
    handleClick(row) {
      console.log(row);
      this.Visible = !this.Visible;
      this.imgvisible = !this.imgvisible;
      this.$nextTick(() => {
        this.detaile = row;
      });
    },
    // initPolice() {
    //   let that = this;
    //   this.selectId.token = this.$VueCookies.get("token");
    //   // department({ department_id: this.userInfo.user.department_id }).then(
    //   //   (res) => {
    //   //     console.log(res);
    //   //   }
    //   // );
    //   department({ department_id: this.userInfo.user.department_id }).then(
    //     (res) => {
    //       // console.log(res);
    //       if (res.code == 200) {
    //         res.data.children.forEach((item) => {
    //           item.label = item.label.slice(6);
    //           if (item.children != undefined) {
    //             item.children.forEach((m) => {
    //               m.label = m.label.slice(9);
    //             });
    //           }
    //         });
    //         that.optionsOne.push(res.data);
    //         // that.optionsOne.children = ;
    //       } else if (res.code == 401) {
    //         // alert();
    //         this.$message({
    //           message: res.message,
    //           type: "warning",
    //           duration: "2000",
    //         });
    //       }
    //     }
    //   );
    // },
    // handleChangexz(e) {
    //   console.log(e[e.length - 1]);
    //   if (e[e.length - 1] != undefined) {
    //     this.formData.department_id = e[e.length - 1];
    //   } else {
    //     this.formData.department_id = "";
    //   }
    //   // console.log(e.pop());
    // },
    // 数据初始化
    initdata() {
      let that = this;
      let loadingInstance = Loading.service({
        target: document.querySelector(".el-table__body-wrapper"),
      });
      imageTextLoggl(this.searchData).then((res) => {
        console.log(res.data);
        if (res.code == 200) {
          loadingInstance.close();

          this.total = res.data.count;
          this.tableData = res.data.res;
          console.log(that.tableData);
        }
      });
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(() => {
          done();
        })
        .catch(() => {});
    },
    // 条件查询
    submitForm(formData) {
      let that = this;
      let loadingInstance = Loading.service({
        target: document.querySelector(".el-table__body-wrapper"),
      });
      this.searchData.ssjwsq = formData.ssjwsq; // 所属派出所
      this.searchData.xm = formData.xm; // 上报人姓名
      this.searchData.dwmc = formData.dwmc; // 上报人姓名
      this.searchData.page = 1;
      if (formData.time == [] || formData.time == null) {
        this.searchData.end_time = "";
        this.searchData.begin_time = "";
      } else {
        this.searchData.end_time = formData.time[1];
        this.searchData.begin_time = formData.time[0];
      }
      console.log(this.searchData);
      imageTextLoggl(this.searchData).then((res) => {
        if (res.code == 200) {
          console.log(res);
          this.currentPage = 1;
          this.pageSize = 10;
          this.total = res.data.count;
          this.tableData = res.data.res;
          console.log(that.tableData);
          // that.$nextTick(() => {
          //   res.data.res.forEach((item) => {
          //     item.showIdCard = false;
          //   });
          //   that.tableData = res.data.res;
          //   this.total = res.data.count;
          //   // 以服务的方式调用的 Loading 需要异步关闭
          loadingInstance.close();
          // });
        } else {
          console.log(res);
          this.$message.error(res.message);
          loadingInstance.close();
          that.tableData = [];
        }
      });
    },
    resetForm() {
      this.$refs["elForm"].resetFields();
      (this.searchData = {
        // xm: "", // 上报人姓名
        begin_time: "", // 开始时间
        end_time: "", // 结束时间
        page: 1,
        pagesize: 10,
        token: JSON.parse(localStorage.getItem("userInfo")).user.token,
      }),
        (this.tableData = []);
      let that = this;
      this.searchData.page = 1;
      this.currentPage = 10;
      let loadingInstance = Loading.service({
        target: document.querySelector(".el-table__body-wrapper"),
      });
      imageTextLoggl(this.searchData).then((res) => {
        console.log(res);
        this.currentPage = 1;
        loadingInstance.close();
        this.total = res.data.count;
        this.tableData = res.data.res;
        console.log(that.tableData);
      });
    },

    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.searchData.pagesize = val;
      this.searchData.page = 1;
      this.currentPage = 1;
      this.initdata();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.searchData.page = val;
      this.initdata();
    },
  },
};
</script>
<style scoped lang="scss" >
#elForm {
  /deep/.el-form-item__content {
    margin-left: 0 !important;
  }
}
.imgWrite-top {
  //
  padding: 10px;
  background-color: white;
  border-radius: 10px;
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-content: center;
  justify-content: space-around;
  align-items: flex-start;
  box-sizing: border-box;
}
.imgWrite-top {
  width: calc(100%);
}

// .auto-width {
//   width: "auto";
// }
.el-table {
  width: calc(100%);
}
/deep/.el-form-item {
  height: 50px;
}

/deep/.el-form-item__label {
  width: 104px !important;
  padding: 0 !important;
}
.warn-content {
  margin-top: 20px;
  //
  height: auto;
  background-color: white;
  border-radius: 10px;
  padding: 10px;
  box-sizing: border-box;
}

.el-table .el-table__cell {
  padding: 12px 0;
  min-width: 0;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: center;
}
.upIpfo {
  display: flex;
  width: 100%;
  //
  justify-content: space-between;
}
.upIpfo p {
  color: #13213b;
  font-size: 14px;
  font-weight: 400;
  width: 50%;
  margin-top: 10px;
  //
  display: inline-block;
  // background-color: skyblue;
}
/deep/.el-table__header-wrapper {
  // border: 1px red solid !important;
  border-radius: 10px 10px 0 0;
}
/deep/.el-table {
  border: 1px #d7dbe3 solid;
  border-radius: 10px;
}
/deep/.has-gutter tr th {
  color: black;
  text-align: center;
  border: 1px d7dbe3 solid;
  background-color: #ecf5ff;
}

/deep/.is-leaf {
  border: 1px #d7dbe3 solid !important;
  border-top: none !important;
  border-left: none !important;
}
/deep/.el-table__cell {
  text-align: center !important;
}
// /deep/.el-table__row {
//   border: 1px red solid !important;
// }
/deep/.el-dialog {
  border-radius: 15px !important;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin-top: 0;
}
/deep/.el-dialog__header {
  text-align: left;
  font-weight: 600;
}
/deep/.el-dialog__body {
  padding: 0 20px 20px 20px !important;
}
// /deep/.el-dialog__body tbody > .el-table__row {
//   color: red !important;
//   /deep/.el-table_1_column_5 {
//     color: red !important;
//   }
// }
/deep/.el-range-editor.el-input__inner {
  position: relative !important;
  right: 20px !important;
  border-radius: 6px !important;
}
/deep/.el-input__inner {
  border: 1px solid #d7dbe3 !important;
  background-color: white !important;
  border-radius: 6px !important;
}
// el-table_1_column_5   el-table__cell
.rowText {
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  /*第几行裁剪*/
  -webkit-box-orient: vertical;
}
::v-deep.el-table th.el-table__cell {
  background-color: #ecf5ff !important;
  width: 64px !important;
  height: 21px !important;
  font-size: 16px !important;
  color: #13213b !important;
}
</style>
